﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.MVC.Model;
using Project.MVC.MsSQLDAL;
namespace Project.MVC.Service
{
    public class ContactServices : IContactServices
    {
        IContactRepository repository = null;
        public ContactServices()
            : this(new ContactRepository())
        {
        }

        public ContactServices(IContactRepository rep)
        {
            repository = rep;
            if (repository == null)
                throw new InvalidOperationException("Repository cann't be null");
        }
        public IQueryable<ContactInfo> GetList2Grid()
        {
            return repository.GetList();
        }
        public ContactInfo GetDefault()
        {
            return repository.GetList().SingleOrDefault();
        }

        public List<ContactInfo> GetList()
        {
            return repository.GetList().ToList();
        }

        public List<ContactInfo> GetList(int start, int offset)
        {
            throw new NotImplementedException();
        }

        public bool Insert(ContactInfo value)
        {
            return repository.Insert(value);
        }

        public bool Update(ContactInfo value)
        {
            return repository.Update(value);
        }

        public bool Delete(ContactInfo value)
        {
            return repository.Delete(value);
        }

        public void SaveChange()
        {
            repository.Commit();
        }

        public int Count()
        {
            return repository.Count();
        }


    
    }
}
